Next: Hanging Semicolons and Commas, Previous: Hanging Braces, Up: Custom Auto-newlines [Contents][Index]
Using a mechanism similar to brace hanging (see Hanging Braces), colons
can also be made to hang using the style variable
c-hanging-colons-alist: when a colon is typed, CC
Mode determines its syntactic context, looks this up in the alist
c-changing-colons-alist and inserts up to two
newlines accordingly. Here, however, If CC Mode fails to find an
entry for a syntactic symbol in the alist, no newlines are
inserted around the newly typed colon.
The syntactic symbols appropriate as keys in this
association list are: case-label,
label, access-label,
member-init-intro, and
inher-intro. See Syntactic
Symbols. Elements with any other value as a key get
ignored.
The action here is simply a list containing
a combination of the symbols before and
after. Unlike in
c-hanging-braces-alist, functions as
actions are not supported; there doesn’t
seem to be any need for them.
In C++, double-colons are used as a scope operator but because these colons always appear right next to each other, newlines before and after them are controlled by a different mechanism, called clean-ups in CC Mode. See Clean-ups, for details.